import matplotlib.pyplot as plt
import numpy as np
import math
# class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
#                'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']




def _plot_image(i, predictions, true_label_indexs, img,class_names):
  true_label_index, img = true_label_indexs[i], img[i]
  plt.grid(False)
  plt.xticks([])
  plt.yticks([])

  plt.imshow(img, cmap=plt.cm.binary)

  predicted_label_index = np.argmax(predictions)
  
  if predicted_label_index == true_label_index:
    color = 'blue'
  else:
    color = 'red'

  plt.xlabel("?->{} {:2.0f}% ({})".format(class_names[predicted_label_index],
                                100*np.max(predictions),
                                class_names[true_label_index]),
                                color=color)
  
def _plot_value_array(i, predictions, true_label):
  true_label = true_label[i]
  plt.grid(False)
  plt.xticks(range(10))
  plt.yticks([])
  thisplot = plt.bar(range(10), predictions, color="#777777")
  plt.ylim([0, 1])
  predicted_label = np.argmax(predictions)

  thisplot[predicted_label].set_color('red')
  thisplot[true_label].set_color('blue')

def plot_result(showIndexArr,predictions,test_labels,test_images,class_names):
    num_cols = 3
    print(">>>>>?",len(showIndexArr))
    num_rows = math.ceil(len(showIndexArr)/num_cols)
    plt.figure(figsize=(2*2*num_cols, 2*num_rows))
    for i in showIndexArr:
        plt.subplot(num_rows, 2*num_cols, 2*i+1)
        _plot_image(i, predictions[i], test_labels, test_images,class_names)
        plt.subplot(num_rows, 2*num_cols, 2*i+2)
        _plot_value_array(i, predictions[i], test_labels)
        plt.tight_layout()
    plt.show()  

#   for i in showIndexArr:
#     plt.figure(figsize=(6,3))
#     plt.subplot(1,2,1)
#     _plot_image(i, predictions[i], test_labels, test_images)
#     plt.subplot(1,2,2)
#     _plot_value_array(i, predictions[i],  test_labels)

#   plt.show()  